#include"Date.h"


Date::Date(int year,int month,int day)
{
	_year = year;
	_month = month;
	_day = day;
}

Date::Date(const Date& a)
{
	_year = a._year;
	_month = a._month;
	_day = a._day;
}

void Date::Print()
{
	cout << _year << '-' << _month << '-' << _day << endl;
}

int Date::Getyear()
{
	return _year;
}
int Date::Getmonth()
{
	return _month;
}
int Date::Getday()
{
	return _day;
}




int getmonth(int year,int month)
{
	assert(year >= 1 && month >= 1 && month < 13);
	int monthday[13] = { 0,31,28,31,30,31,30,31,31,30,31,30,31 };
	if ((month == 2) && ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0)))
	{
		return 29;
	}
	else
	{
		return monthday[month];
	}
}

Date& Date::operator+=(int day)
{
	_day += day;
	while (_day >getmonth(_year,_month))
	{
		_day -= getmonth(_year,_month);
		_month++;
		if (_month > 12)
		{
			_month = 1;
			_year++;
		}
	}
	return *this;
}

Date Date::operator+(int day)
{
	Date temp(*this);
	temp += day;
	return temp;
}

Date& Date::operator-=(int day)
{
	_day -= day;
	while (_day <= 0)
	{
		_month -= 1;
		if (_month == 0)
		{
			_month = 12;
			_year--;
		}
		_day += getmonth(_year, _month);
	}
	return *this;
}

Date Date::operator-(int day)
{
	Date temp(*this);
	temp -= day;
	return temp;
}




Date& Date::operator -- ()
{
	_day--;
	if (_day == 0)
	{
		if (_month == 1)
		{
			_month = 12;
			_year--;
		}
		else
		{
			_month--;
		}
		_day += getmonth(_year, _month);
	}
	return *this;
}

Date Date::operator--(int)
{
	Date temp(*this);
	--(*this);
	return temp;
}

Date& Date::operator++()
{
	_day++;
	if (_day > getmonth(_year, _month))
	{
		_month++;
		_day = 1;
		if (_month > 12)
		{
			_year++;
			_month = 1;
		}
	}
	return *this;
}

Date Date::operator++(int)
{
	Date temp(*this);
	++(*this);
	return temp;
}



bool Date::operator>(Date y)
{
	if (this->Getyear() > y.Getyear())
	{
		return true;
	}
	else if (this->Getyear() == y.Getyear())
	{
		if (this->Getmonth() > y.Getmonth())
		{
			return true;
		}
		else if (this->Getmonth() < y.Getmonth())
		{
			return false;
		}
		else
		{
			if (this->Getday() > y.Getday())
			{
				return true;
			}
			else
			{
				return false;
			}
		}
	}
	else
	{
		return false;
	}
}

bool Date::operator<(Date y)
{
	return (_year < y.Getyear() && _month < y.Getmonth() && _day < y.Getday());
}

bool Date::operator==(Date y)
{
	return _year == y._year && _month == y._month && _day == y._day; 
}

bool Date::operator>=(Date y)
{
	return !(*this < y);
}

bool Date::operator<=(Date y)
{
	return !(*this > y);
}

bool Date::operator!=(Date y)
{
	return (_year != y._year || _month != y._month || _day != y._day);
}





